<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
      sumTo(3) return 3 + sumTo(2)=3;
      sumTo(2) return 2 + sumTo(1)=1;
      sumTo(1) return 1
      */
      function sumTo(n) {
        return ((n + 1) * n) / 2;
      }
      console.log(sumTo(3)); //6
    </script>
  </body>
</html>
